extends admin-layout

block mainbody
  .buttons
    h1 Events
    p
    form(method='POST' action='/admin/create/event')
      button.add(type="submit")
        .icon &plus;
        p New
  each event in events
    hr
    form(method='post' action='/admin/update/event')
      table
        tr
          th.label #{event['id']}
          th #{event['title']}
        each value, field in event
          if field != 'id'
            - var inputId = "_" + event['id'] + "_" + field;
            - var useToday = "document.getElementById('_" + event['id']
            - useToday += "_" + field + "').value=todayString()";
            tr
              td.label: label(for=field) #{field}:
              if field == 'body'
                td: textarea(name=field id=inputId)
                  =event[field]
              else
                td.buttons
                  if field == 'date'
                    input(type="text", size=18, name=field, value=event[field] id=inputId)
                    p
                    button(type="button" onclick=useToday)
                      div today
                  else
                    input(type="text", size=28, name=field, value=event[field] id=inputId)
        tr.norule
          td: input(type="hidden" name="id" value=event['id'])
          td.buttons
            button.update(type="submit" name="update")
              .icon &check;
              p Update
            .space
            button.delete(name="action" value="delete" onclick="return confirm('Are you sure?')")
              .icon X
              p Delete
    p